package com.wgl.yygh.api;

import com.wgl.model.user.UserInfo;
import com.wgl.model.vo.user.LoginVo;
import com.wgl.model.vo.user.UserAuthVo;
import com.wgl.yygh.result.Result;
import com.wgl.yygh.serivice.UserInfoService;
import com.wgl.yygh.util.AuthContextHolder;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author wgl
 * @version 1.0.0
 * @ClassName UserInfoApiController.java
 * @Description TODO
 * @createTime 2022年02月09日 14:09:00
 */
@RestController
@RequestMapping("/api/user")
public class UserInfoApiController {

    @Resource
    private UserInfoService userInfoService;


    /**
    * @Author: Wgl
    * @Description: 用户手机登录
    * @Date: 2022/2/9 14:20;
    * @param loginVo: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo){
        Map<String,Object> map =userInfoService.loginUser(loginVo);

        return Result.ok(map);
    }

    /**
    * @Author: Wgl
    * @Description: 用户认证
    * @Date: 2022/2/10 15:48;
    * @param userAuthVo:
     * @param request: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @PostMapping("/auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request){
        //用户id 和认证数据
        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);

        return Result.ok();
    }

    @GetMapping("/auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        UserInfo byId = userInfoService.getById(userId);
        return Result.ok(byId);
    }
}
